<template>
    <div class="app-container">
        <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true"
            label-width="90px">
            <el-form-item label="订单号" prop="orderNum" label-width="100px">
                <el-input v-model="queryParams.orderNum" placeholder="订单号" clearable style="width: 250px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="客户姓名" prop="clientName" label-width="100px">
                <el-input v-model="queryParams.clientName" placeholder="客户姓名" clearable style="width: 250px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="客户手机号码" prop="clientPhone" label-width="100px">
                <el-input v-model="queryParams.clientPhone" placeholder="客户手机号码" clearable style="width: 250px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="催收员姓名" prop="collectionName" label-width="100px">
                <el-input v-model="queryParams.collectionName" placeholder="催收员姓名" clearable style="width: 250px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="还款方式" prop="paymentMethod" label-width="100px">
                <el-select v-model="queryParams.paymentMethod" placeholder="请选择" clearable style="width: 250px">
                    <!-- 字典状态，dict.type.你添加进字典的类型 -->
                    <el-option v-for="dict in dict.type.loan_info_payment_status" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="账单状态" prop="loanStatus" label-width="100px">
                <el-select v-model="queryParams.loanStatus" placeholder="请选择" clearable style="width: 250px">
                    <!-- 字典状态，dict.type.你添加进字典的类型 -->
                    <el-option v-for="dict in dict.type.loan_info_applicant_status" :key="dict.value"
                        :label="dict.label" :value="dict.value"
                        v-if="dict.value == 12 || dict.value == 13 || dict.value == 14 || dict.value == 16" />
                </el-select>
            </el-form-item>
            <el-form-item label="渠道筛选" prop="channelType" label-width="100px">
                <el-select v-model="queryParams.channelType" placeholder="请选择" clearable style="width: 250px">
                    <!-- 字典状态，dict.type.你添加进字典的类型 -->
                    <el-option v-for="dict in dict.type.channel_channel_type" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="实际还款日期" label-width="100px">
                <el-date-picker v-model="queryParams.actualPaymentTime" type="date" style="width: 250px"
                    value-format="yyyy-MM-dd hh:mm:ss" placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="订单放款日期" label-width="100px">
                <el-date-picker v-model="dateRange" style="width: 250px" value-format="yyyy-MM-dd" type="daterange"
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
            </el-form-item>
            <el-form-item label="负责人" prop="operatorName" label-width="100px">
                <el-input v-model="queryParams.operatorName" placeholder="负责人" clearable style="width: 250px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <div style="margin-right: 50px;">
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                </div>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button v-hasPermi="['system:post:export']" type="warning" plain icon="el-icon-download" size="mini"
                    @click="handleExport">导出</el-button>
            </el-col>
            <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
        </el-row>
        <!-- data=你后台查出的数据 -->
        <el-table v-loading="loading" :data="billList">
            <el-table-column type="selection" width="40" align="center" />
            <el-table-column label="订单号" align="center" prop="orderNum" />
            <el-table-column label="客户姓名" align="center" prop="clientName" />
            <el-table-column label="手机号" align="center" prop="clientPhone" />
            <el-table-column label="账单金额" align="center" prop="loanAmount" />
            <el-table-column label="实际还款金额" align="center" prop="actualPaymentTotal" />
            <el-table-column label="账单状态" align="center" prop="applicantStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.loan_info_applicant_status" :value="scope.row.loanStatus" />
                </template>
            </el-table-column>
            <el-table-column label="应还款时间" align="center" prop="essentialPayDeadline" lable-width="auto">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.essentialPayDeadline) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="实际还款时间" align="center" prop="actualPaymentTime" lable-width="auto">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.actualPaymentTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="负责人" align="center" prop="operatorName" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <router-link :to="'/loan/billList-checkDetail/index/'+ scope.row.loanInfoId + '/' + scope.row.clientId" class="link-type">
                        <el-button v-hasPermi="['system:user']" size="mini" type="text">审核详情</el-button>
                    </router-link>
                    <router-link :to="'/loan/billList-loanDetail/index/'+ scope.row.loanInfoId + '/' + scope.row.clientId" class="link-type">
                        <el-button v-hasPermi="['system:user']" size="mini" type="text" v-if="scope.row.loanStatus != 14">放款详情</el-button>
                    </router-link>
                    <el-button v-hasPermi="['system:user']" size="mini" type="text" @click="clientRemark(scope.row.clientId)">客户备注
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form">
                <el-form-item prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
            </el-form>
            <div slot="footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script>
// 导入api
import { findBillList, clientRemark } from '@/api/billList'

export default {
    name: 'FirstTrial',
    // 字典导入
    dicts: ['loan_info_applicant_status', 'loan_info_audit_result', 'loan_info_payment_status', 'channel_channel_type'],
    data() {
        return {
            open: false,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 
            billList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                orderNum: undefined,
                clientName: undefined,
                clientPhone: undefined,
                collectionName: undefined,
                paymentMethod: undefined,
                loanStatus: undefined,
                channelType: undefined,
                actualPaymentTime: undefined,
                operatorName: undefined
            },
            // 表单参数
            form: {
                clientId: undefined,
                remark: undefined,
                status: '0'
            },
            data:{
                ids:this.ids
            }
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            this.loading = true
            findBillList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
                console.log(res)
                this.billList = res.rows
                console.log(this.billList)
                this.total = res.total
                this.loading = false
            }).catch()

            this.loading = false
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        cancel() {
            this.open = false
            this.reset()
        },
        reset() {
            this.form = {
                clientId: undefined,
                remark: undefined,
                status: '0'
            }
            this.resetForm('form')
        },
        handleExport() {
            console.log(this.exportParams)
            this.download('bill/exportXlsx', this.data, `账单列表_${new Date().getTime()}.xlsx`)
        },
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.postId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        submitForm() {
            this.$refs['form'].validate(valid => {
                if (valid) {
                    clientRemark(this.form).then(res=>{
                        console.log(res)
                        if(res.code == 200){
                            this.$modal.msgSuccess(res.msg)
                        }else{
                            this.$modal.msgSuccess(res.msg)
                        }
                        this.open = false
                    }).catch()
                }
            })
            console.log('hhhhhhh')
        },
        clientRemark(clientId) {
            this.reset()
            this.form.clientId = clientId
            this.open = true
            this.title = '客户备注'
        }
    }

}

</script>
  
  